home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Compilers / digital marsC compier / dm / include / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-20  |  9.6 KB  |  400 lines

  1. /* Copyright (C) 1986-2001 by Digital Mars. $Revision: 1.1.1.2 $ */
  2. #if __SC__ || __RCC__
  3. #pragma once
  4. #endif
  5.  
  6. #ifndef __STDIO_H
  7. #define __STDIO_H 1
  8.  
  9. #if __cplusplus
  10. extern "C" {
  11. #endif
  12.  
  13. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  14. #ifndef _CRTAPI1
  15. #define _CRTAPI1 __cdecl
  16. #endif
  17.  
  18.  
  19. /* Define _CRTAPI2 (for compatibility with the NT SDK) */
  20. #ifndef _CRTAPI2
  21. #define _CRTAPI2 __cdecl
  22. #endif
  23.  
  24. /* Define CRTIMP */
  25. #ifndef _CRTIMP
  26. #if defined(_WIN32) && defined(_DLL)
  27. #define _CRTIMP  __declspec(dllimport)
  28. #else
  29. #define _CRTIMP
  30. #endif
  31. #endif
  32.  
  33. #if __OS2__ && __INTSIZE == 4
  34. #define __CLIB    __stdcall
  35. #else
  36. #define __CLIB    __cdecl
  37. #endif
  38.  
  39. #if M_UNIX || M_XENIX || __NT__
  40. #define _NFILE    60
  41. #else
  42. #define _NFILE    40
  43. #endif
  44.  
  45.  
  46. #define SEEK_SET    0
  47. #define SEEK_CUR    1
  48. #define SEEK_END    2
  49.  
  50. #ifndef NULL
  51. #ifdef __cplusplus
  52. #define NULL 0
  53. #else
  54. #define NULL ((void *)0)
  55. #endif
  56. #endif
  57.  
  58. #if M_UNIX || M_XENIX
  59. #define BUFSIZ        4096
  60. extern char * __cdecl _bufendtab[];
  61. #elif __INTSIZE == 4
  62. #define BUFSIZ        0x4000
  63. #else
  64. #define BUFSIZ        1024
  65. #endif
  66.  
  67. #if __INTSIZE == 2 && (__SMALL__ || __MEDIUM__)
  68. #define BIGBUF        (20 * 1024)
  69. #endif
  70.  
  71. typedef unsigned size_t;
  72.  
  73. #ifndef __STDC__
  74.  
  75. #if !defined(_WCHAR_T_DEFINED)
  76. typedef unsigned short wchar_t;
  77. #define _WCHAR_T_DEFINED 1
  78. #endif
  79.  
  80. typedef wchar_t wint_t;
  81. typedef wchar_t wctype_t;
  82. #endif
  83.  
  84. #define EOF (-1)
  85.  
  86. #ifndef __STDC__
  87. #define WEOF (wint_t) (0xFFFF)
  88. #endif
  89.  
  90. #ifndef __FILE_DEFINED
  91. #pragma pack(1)
  92. #define __FILE_DEFINED 1
  93. typedef struct _iobuf
  94. {
  95. #if M_UNIX || M_XENIX
  96.     int    _cnt;
  97.     char    *_ptr;
  98.     char    *_base;
  99.     char    _flag;
  100.     char    _file;
  101. #define _bufsize(f) (_bufendtab[(f)->_file] - (f)->_base)
  102. #elif __OS2__ && __INTSIZE == 4
  103.     char    *_ptr;
  104.     int    _cnt;
  105.     char    *_base;
  106.     int    _flag;
  107.     int    _file;
  108.     int    _charbuf;
  109.     int    _bufsiz;
  110.     int    __tmpnum;
  111. #define _bufsize(f) ((f)->_bufsiz)
  112. #elif __NT__
  113.     char    *_ptr;
  114.     int    _cnt;
  115.     char    *_base;
  116.     int    _flag;
  117.     int    _file;
  118.     int    _charbuf;
  119.     int    _bufsiz;
  120.     int    __tmpnum;
  121. #define _bufsize(f) ((f)->_bufsiz)
  122. #else
  123.     char    *_ptr;
  124.     int    _cnt;
  125.     char    *_base;
  126.     int    _flag;
  127.     int    _file;
  128.     unsigned _bufsiz;
  129. #ifdef    BIGBUF
  130.     int    _seg;
  131. #endif
  132. #define _bufsize(f) ((f)->_bufsiz)
  133. #endif
  134. } FILE;
  135. #pragma pack()
  136. #endif
  137.  
  138. #define _F_RDWR 0x0003
  139. #define _F_READ 0x0001
  140. #define _F_WRIT 0x0002
  141. #define _F_BUF  0x0004
  142. #define _F_LBUF 0x0008
  143. #define _F_ERR  0x0010
  144. #define _F_EOF  0x0020
  145. #define _F_BIN  0x0040
  146. #define _F_IN   0x0080
  147. #define _F_OUT  0x0100
  148. #define _F_TERM 0x0200
  149.  
  150. #ifdef M_ELF
  151. #define _iob __iob
  152. #endif
  153.  
  154. #if defined (_DLL)
  155.  
  156. #define _iob ( _p_iob() )
  157. extern FILE * _p_iob(void);
  158.  
  159. #else
  160.  
  161. extern    FILE __cdecl _iob[_NFILE];
  162.  
  163. #endif
  164.  
  165. #define _IOREAD        1
  166. #define _IOWRT        2
  167. #define _IONBF        4
  168. #define _IOMYBUF    8
  169. #define _IOEOF        0x10
  170. #define _IOERR        0x20
  171. #define _IOLBF        0x40
  172. #define _IOSTRG         0x40
  173. #define _IORW        0x80
  174. #define _IOFBF        0
  175. #define _IOAPP        0x200
  176. #if M_UNIX || M_XENIX
  177. #define _IOTRAN        0
  178. #else
  179. #define _IOTRAN        0x100
  180. #ifdef    BIGBUF
  181. #define _IOBIGBUF    0x400
  182. #endif
  183. #endif
  184.  
  185. #define stdin    (&_iob[0])
  186. #define stdout    (&_iob[1])
  187. #define stderr    (&_iob[2])
  188.  
  189. #if M_UNIX || M_XENIX
  190. #define FOPEN_MAX    60
  191. #define FILENAME_MAX    255
  192.  
  193. #if !__STDC__ || defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
  194. char * __cdecl ctermid(char *);
  195. #define L_ctermid 9
  196. #endif
  197.  
  198. #else
  199. #ifndef __STDC__
  200. #ifndef __NT__
  201. #define stdaux    (&_iob[3])
  202. #define stdprn    (&_iob[4])
  203. #define _stdaux stdaux
  204. #define _stdprn stdprn
  205. #endif
  206. #endif
  207. #define FOPEN_MAX    20
  208. #if defined(_WIN32)
  209. #define FILENAME_MAX 256  /* 255 plus NULL */
  210. #else
  211. #define FILENAME_MAX    128
  212. #endif
  213. #endif
  214.  
  215. #if M_UNIX || M_XENIX
  216. #define _P_tmpdir    "/usr/tmp/"
  217. #define _wP_tmpdir    L"/usr/tmp/"
  218. #else
  219. #define _P_tmpdir    "\\"
  220. #define _wP_tmpdir    L"\\"
  221. #endif
  222. #define P_tmpdir    _P_tmpdir
  223. #define wP_tmpdir    _wP_tmpdir
  224. #if !defined(_WIN32)
  225. #define L_tmpnam    sizeof(_P_tmpdir)+8
  226. #else
  227. #define L_tmpnam    sizeof(_P_tmpdir)+12
  228. #endif
  229. #define TMP_MAX        32767
  230. #define _SYS_OPEN       20
  231. #define SYS_OPEN        _SYS_OPEN
  232.  
  233. typedef long fpos_t;
  234.  
  235. typedef char *va_list;
  236.  
  237. int    __CLIB fwide(FILE *stream, int mode);
  238. char *    __CLIB tmpnam(char *);
  239. FILE *    __CLIB fopen(const char *,const char *);
  240. FILE *    __CLIB _fsopen(const char *,const char *,int );
  241. FILE *    __CLIB freopen(const char *,const char *,FILE *);
  242. int    __CLIB fseek(FILE *,long,int);
  243. long    __CLIB ftell(FILE *);
  244. char *    __CLIB fgets(char *,int,FILE *);
  245. int    __CLIB fgetc(FILE *);
  246. int   __CLIB _fgetchar(void);
  247. int    __CLIB fflush(FILE *);
  248. int    __CLIB fclose(FILE *);
  249. int    __CLIB fputs(const char *,FILE *);
  250. int    __CLIB getc(FILE *);
  251. int    __CLIB getchar(void);
  252. char *    __CLIB gets(char *);
  253. int    __CLIB fputc(int,FILE *);
  254. int   __CLIB _fputchar(int);
  255. int    __CLIB putc(int,FILE *);
  256. int    __CLIB putchar(int);
  257. int    __CLIB puts(const char *);
  258. int    __CLIB ungetc(int,FILE *);
  259. size_t    __CLIB fread(void *,size_t,size_t,FILE *);
  260. size_t    __CLIB fwrite(const void *,size_t,size_t,FILE *);
  261. int    __cdecl printf(const char *,...);
  262. int    __cdecl fprintf(FILE *,const char *,...);
  263. int    __CLIB  vfprintf(FILE *,const char *,va_list);
  264. int    __CLIB  vprintf(const char *,va_list);
  265. int    __cdecl sprintf(char *,const char *,...);
  266. int    __CLIB  vsprintf(char *,const char *,va_list);
  267. int    __cdecl scanf(const char *,...);
  268. int    __cdecl fscanf(FILE *,const char *,...);
  269. int    __cdecl sscanf(const char *,const char *,...);
  270. void    __CLIB setbuf(FILE *,char *);
  271. int    __CLIB setvbuf(FILE *,char *,int,size_t);
  272. int    __CLIB remove(const char *);
  273. int    __CLIB rename(const char *,const char *);
  274. void    __CLIB rewind(FILE *);
  275. void    __CLIB clearerr(FILE *);
  276. int    __CLIB feof(FILE *);
  277. int    __CLIB ferror(FILE *);
  278. void    __CLIB perror(const char *);
  279. int    __CLIB fgetpos(FILE *,fpos_t *);
  280. int    __CLIB fsetpos(FILE *,const fpos_t *);
  281. FILE *    __CLIB tmpfile(void);
  282. int    __CLIB _rmtmp(void);
  283. int     __CLIB _fillbuf(FILE *);
  284. int     __CLIB _flushbu(int, FILE *);
  285. /*#define _filbuf _fillbuf*/
  286. /*#define _flsbuf _flushbu*/
  287.  
  288. int __CLIB getw(FILE *FHdl);
  289. #define _getw  getw
  290. int __CLIB putw(int Word, FILE *FilePtr);
  291. #define _putw putw
  292.  
  293. #if __cplusplus
  294. inline int __CLIB getchar()        { return getc(stdin);        }
  295. inline int __CLIB putchar(int c)    { return putc(c,stdout);    }
  296. inline int __CLIB getc(FILE *fp)    { return fgetc(fp);        }
  297. inline int __CLIB putc(int c,FILE *fp)    { return fputc(c,fp);        }
  298. inline int __CLIB ferror(FILE *fp)    { return fp->_flag&_IOERR;    }
  299. inline int __CLIB feof(FILE *fp)    { return fp->_flag&_IOEOF;    }
  300. inline void __CLIB clearerr(FILE *fp)    { fp->_flag &= ~(_IOERR|_IOEOF); }
  301. inline void __CLIB rewind(FILE *fp)    { fseek(fp,0L,SEEK_SET); fp->_flag&=~_IOERR; }
  302. #else
  303. #define getchar()    getc(stdin)
  304. #define putchar(c)      putc(c,stdout)
  305.  
  306. #if !defined(_WINDOWS)
  307. int __cdecl putch(int);
  308. #define _putch          putch
  309. #endif
  310.  
  311. #define getc(fp)    fgetc(fp)
  312. #define putc(c,fp)    fputc((c),(fp))
  313. #define ferror(fp)    ((fp)->_flag&_IOERR)
  314. #define feof(fp)    ((fp)->_flag&_IOEOF)
  315. #define clearerr(fp)    ((void)((fp)->_flag&=~(_IOERR|_IOEOF)))
  316. #define rewind(fp)    ((void)(fseek(fp,0L,SEEK_SET),((fp)->_flag&=~_IOERR)))
  317. #endif
  318.  
  319. #ifndef __STDC__
  320. #define fileno(fp)    ((fp)->_file)
  321. #define _fileno(fp)     ((fp)->_file)
  322.  
  323. #if M_UNIX || M_XENIX
  324. int    __cdecl pclose(FILE *fp);
  325. FILE *    __cdecl popen(const char *command,const char *t);
  326. #endif
  327.  
  328. int     __CLIB unlink(const char *);
  329. #define _unlink unlink
  330.  
  331. FILE *    __CLIB fdopen(int, const char *);
  332. int   __CLIB fgetchar(void);
  333. int   __CLIB fputchar(int);
  334. int    __CLIB fcloseall(void);
  335. long    __CLIB filesize(const char *);
  336. int    __CLIB flushall(void);
  337. int    __CLIB getch(void);
  338. int    __CLIB getche(void);
  339. int     __CLIB kbhit(void);
  340. char *  __CLIB tempnam (char *dir, char *pfx);
  341. int     __CLIB _snprintf(char *,size_t,const char *,...);
  342. int    __CLIB _vsnprintf(char *,size_t,const char *,va_list);
  343. #define _flushall flushall
  344. #define _fcloseall fcloseall
  345. #define _fdopen fdopen
  346. #define _tempnam tempnam
  347. #define _getche getche
  348. #define _getch getch
  349. #endif
  350.  
  351. #ifdef __NT__
  352. #ifndef __STDC__
  353. wchar_t * __CLIB _wtmpnam(wchar_t *);
  354. FILE * __CLIB _wfopen(const wchar_t *, const wchar_t *);
  355. FILE * __CLIB _wfsopen(const wchar_t *, const wchar_t *, int);
  356. FILE * __CLIB _wfreopen(const wchar_t *, const wchar_t *, FILE *);
  357. wchar_t * __CLIB fgetws(wchar_t *, int, FILE *);
  358. int __CLIB fputws(const wchar_t *, FILE *);
  359. wchar_t * __CLIB _getws(wchar_t *);
  360. int __CLIB _putws(const wchar_t *);
  361. int __CLIB wprintf(const wchar_t *, ...);
  362. int __CLIB fwprintf(FILE *, const wchar_t *, ...);
  363. int __CLIB vwprintf(const wchar_t *, va_list);
  364. int __CLIB vfwprintf(FILE *, const wchar_t *, va_list);
  365. int __CLIB swprintf(wchar_t *, const wchar_t *, ...);
  366. int __CLIB vswprintf(wchar_t *, const wchar_t *, va_list);
  367. int __CLIB _snwprintf(wchar_t *, size_t, const wchar_t *, ...);
  368. int __CLIB _vsnwprintf(wchar_t *, size_t, const wchar_t *, va_list);
  369. int __CLIB wscanf(const wchar_t *, ...);
  370. int __CLIB fwscanf(FILE *, const wchar_t *, ...);
  371. int __CLIB swscanf(const wchar_t *, const wchar_t *, ...);
  372. int __CLIB _wremove(const wchar_t *);
  373. void __CLIB _wperror(const wchar_t *);
  374. FILE * __CLIB _wfdopen(int, const wchar_t *);
  375. wchar_t * __CLIB _wtempnam(wchar_t *, wchar_t *);
  376. #if M_UNIX || M_XENIX
  377. FILE * __CLIB _wpopen(const wchar_t *, const wchar_t *);
  378. #endif
  379. wint_t __CLIB fgetwc(FILE *);
  380. wint_t __CLIB _fgetwchar(void);
  381. wint_t __CLIB fputwc(wint_t, FILE *);
  382. wint_t __CLIB _fputwchar(wint_t);
  383. wint_t __CLIB getwc(FILE *);
  384. wint_t __CLIB getwchar(void);
  385. wint_t __CLIB putwc(wint_t, FILE *);
  386. wint_t __CLIB putwchar(wint_t);
  387. wint_t __CLIB ungetwc(wint_t, FILE *);
  388. #define getwchar()    fgetwc(stdin)
  389. #define putwchar(_c)    fputwc((_c),stdout)
  390. #define getwc(_stm)    fgetwc(_stm)
  391. #define putwc(_c,_stm)    fputwc(_c,_stm)
  392. #endif
  393. #endif
  394.  
  395. #if __cplusplus
  396. }
  397. #endif
  398.  
  399. #endif
  400.